package database;

import java.sql.ResultSet;
import java.sql.SQLException;

public class DatabaseOperationsUsers {


    private ConnectionDB conn;

    
    public DatabaseOperationsUsers(ConnectionDB conn) {
        this.conn = conn;
    }


    public boolean existsUser(String email)
            throws SQLException {
        ResultSet resultQuery = conn.executeSelect("call existsUser('" + email + "')");
        boolean   exists      = false;

        if (resultQuery.next()) 
            exists = true;
       
        resultQuery.close();
        conn.closeStatement();

        return exists;
    }


    public boolean verifyPassword(String email, String password)
            throws SQLException {
        ResultSet resultQuery = conn.executeSelect("call verifyPassword('" + email + "','" + password + "')");
        boolean   exists      = false;

        if (resultQuery.next()) 
            exists = true;
        
        resultQuery.close();
        conn.closeStatement();

        return exists;
    }


    public void insertUser(String email, String password, String name, String zipcode, String location)
            throws SQLException {
        conn.executeUpdate("call createUser('" + email + "','" + password + "','" + name + "','" + zipcode + "','"+location+"')");
        conn.closeStatement();
    }

    
    public void setZipcodeLocationtUser(String email, String zipcode, String location)
            throws SQLException {
        conn.executeUpdate("call setZipcodeLocationtUser('" + email + "','" + zipcode + "','"+location+"')");
        conn.closeStatement();
    }

    
}

